<% @page_title = "多背一公斤 | #{@school.title}" -%>

<% content_for :sidebar do -%>
  <h2><%= link_to "上传学校的照片", new_photo_url(:school_id => @school.id) %></h2>
  
  <% if @school.editable_by?(current_user) -%>
    <% if @school.is_meta? -%>
      <h2><%= link_to "完善学校信息", edit_school_url(@school.id) %></h2>
    <% else -%>
      <%= link_to "编辑学校信息", edit_school_url(@school.id) %>
    <% end -%>
    
    <%= link_to "删除（放入回收站）", school_url(@school), :confirm => "学校信息会被放入回收站，只有网站管理员才能恢复。确定删除么？", :method => :delete %>
  <% end -%>
  
  <% if logged_in? && current_user.is_admin? -%>
    <h2><%= link_to "添加一个学生信息", new_student_url(@school.id) %></h2>
  <% end -%>
<% end -%>

<h1><%= h @school.title %></h1>

<% if @school.is_meta -%>

<div class="dbb">
  <table border="0" cellspacing="5" cellpadding="0" width="100%">
  <tr>
    <td width="20%"><label for="area">学校所在地区：</label></td>
    <td><%= areas_crumble_path_with_link(@school.area){|p| p.title} %></td>
  </tr>
  <tr>
    <td><label for="address">学校地址：</label></td>
    <td><%= h @school.address %></td>
  </tr>
  <tr>
    <td><label for="telephone">学校电话：</label></td>
    <td><%= h @school.telephone %></td>
  </tr>
  <tr>
    <td><label for="master">校长姓名：</label></td>
    <td><%= h @school.master %></td>
  </tr>
  <tr>
    <td><label for="contact_name">学校联系人：</label></td>
    <td><%= h @school.contact_name %></td>
  </tr>
  <tr>
    <td><label for="contact_role">联系人职务：</label></td>
    <td><%= h @school.contact_role %></td>
  </tr>
  <tr>
    <td><label for="contact_telephone">联系人电话：</label></td>
    <td><%= h @school.contact_telephone %></td>
  </tr>
</table>
</div>
<% unless @school.advice_html.blank? -%>
<table border="0" cellspacing="5" cellpadding="0" width="100%">
  <tr>
    <td width="120" valign="top"><label for="advice">受灾情况和物资需求：</label></td>
  </tr>
  <tr>
    <td><%= @school.advice_html %></td>
  </tr>
</table>
<% end -%>

<% else -%>

  <p><%= link_to h(@school.submitor.login), user_path(@school.submitor.id) %> <span class="tip">提交于</span> <%= show_date @school.created_at %></p>
  <ul id="tabnav" class="school-nav">
  	<li id="base-li" class="current"><a href="javascript:show_form('base')" title="学校基本信息">学校基本信息</a></li>
  	<li id="traffic-li"><a href="javascript:show_form('traffic')" title="交通指南">交通指南</a></li>
  	<li id="require-li"><a href="javascript:show_form('require')" title="学校需求">学校需求</a></li>
  	<li id="finder-li"><a href="javascript:show_form('finder')" title="信息收集人">信息收集人</a></li>
  </ul>
  <div id="base-form">
    <table border="0" cellspacing="5" cellpadding="0">
      <tr>
        <td><label for="area">学校所在地区：</label></td>
        <td><%= areas_crumble_path_with_link(@school.area){|p| p.title} %></td>
      </tr>
      <tr>
        <td><label for="address">学校地址：</label></td>
        <td><%= h @school.address %></td>
      </tr>
      <tr>
        <td><label for="zipcode">邮政编码：</label></td>
        <td><%= h @school.zipcode %></td>
      </tr>
      <tr>
        <td><label for="master">校长姓名：</label></td>
        <td><%= h @school.master %></td>
      </tr>
      <tr>
        <td><label for="telephone">学校电话：</label></td>
        <td><%= h @school.telephone %></td>
      </tr>
      <tr>
        <td><label for="contact_name">学校联系人：</label></td>
        <td><%= h @school.contact_name %></td>
      </tr>
      <tr>
        <td><label for="contact_role">联系人职务：</label></td>
        <td><%= h @school.contact_role %></td>
      </tr>
      <tr>
        <td><label for="contact_telephone">联系人电话：</label></td>
        <td><%= h @school.contact_telephone %></td>
      </tr>
      <tr>
        <td><label for="contact_email">联系人邮件：</label></td>
        <td><%= h @school.contact_email %></td>
      </tr>
      <tr>
        <td><label for="level_amount">学制：</label></td>
        <td><%= h @school.level_amount %></td>
      </tr>
      <tr>
        <td><label for="teacher_amount">教职工数：</label></td>
        <td><%= h @school.teacher_amount %></td>
      </tr>
      <tr>
        <td><label for="class_amount">班级数：</label></td>
        <td><%= h @school.class_amount %></td>
      </tr>
      <tr>
        <td><label for="student_amount">在校生数：</label></td>
        <td><%= h @school.student_amount %></td>
      </tr>
      <tr>
        <td><label for="has_library">是否有图书室：</label><br />
            <label for="book_amount">现有图书：</label></td>
        <td><%= Status::School::RadioBox::status_for(@school.has_library) %><br />
            <%= h @school.book_amount %> 册</td>
      </tr>
      <tr>
        <td><label for="has_pc">是否有电脑：</label><br />
            <label for="pc_amount">现有电脑：</label><br />
            <label for="has_internet">是否能上网：</label></td>
        <td><%= Status::School::RadioBox::status_for(@school.has_pc) %><br />
            <%= h @school.pc_amount %> 台<br />
            <%= Status::School::RadioBox::status_for(@school.has_internet) %></td>
      </tr>
      <tr>
        <td class="label"><label for="incoming_from">乡村主要收入来源：</label></td>
        <td><%= h @school.incoming_from %><br />
    		    <%= h @incoming_from %></td>
      </tr>
      <tr>
        <td><label for="incoming_average">当地年人均收入：</label></td>
        <td><%= Status::School::INCOMING_AVERAGE[@school.incoming_average.to_i] %></td>
      </tr>
      <tr>
        <td class="label"><label for="has_ngo">是否有公益组织或<br />民间人士资助：</label></td>
        <td><%= Status::School::RadioBox::status_for(@school.has_ngo) %></td>
      </tr>
      <% if @school.has_ngo == Status::School::RadioBox::YES %>
      <tr>
        <td><label for="ngo_name">组织名称：</label></td>
        <td><%= h @school.ngo_name %></td>
      </tr>
      <tr>
        <td><label for="ngo_start_at">开展时间：</label></td>
        <td><%= h @school.ngo_start_at %></td>
      </tr>
      <tr>
        <td><label for="ngo_contact_name">联系人：</label></td>
        <td><%= h @school.ngo_contact_name %></td>
      </tr>
      <tr>
        <td><label for="ngo_contact_via">联系方式：</label></td>
        <td><%= h @school.ngo_contact_via %></td>
      </tr>
      <% end %>
      <tr>
        <td width="120"><label for="advice">建议和备注：</label></td>
        <td><%= simple_format @school.advice %></td>
      </tr>  
    </table>
  </div>
  <div id="traffic-form" style="display:none">
    <table border="0" cellspacing="5" cellpadding="0">
      <tr>
        <td><label for="traffic_sights">附近景点：</label></td>
        <td><%= h @school.traffic_sights %></td>
      </tr>
      <tr>
        <td><label for="traffic_type">交通方式：</label></td>
        <td><%= h @school.traffic_type %></td>
      </tr>
      <tr>
        <td><label for="traffic_duration">路程时间：</label></td>
        <td><%= h @school.traffic_duration %> 小时</td>
      </tr>
      <tr>
        <td class="label"><label for="traffic_description">路程攻略：</label></td>
        <td><%= simple_format @school.traffic_description %></td>
      </tr>
      <tr>
        <td><label for="traffic_charge">交通费用：</label></td>
        <td><%= h @school.traffic_charge %> 元</td>
      </tr>
    </table>
  </div>
  <div id="require-form" style="display:none">
    <table border="0" cellspacing="5" cellpadding="0">
      <tr>
        <td><label for="books_need">书籍类：</label></td>
        <td><%= h @school.books_need %></td>
      </tr>
      <tr>
        <td><label for="stationaries_need">文具类：</label></td>
        <td><%= h @school.stationaries_need %></td>
      </tr>
      <tr>
        <td><label for="sports_need">文体类：</label></td>
        <td><%= h @school.sports_need %></td>
      </tr>
      <tr>
        <td><label for="clothes_need">衣服类：</label></td>
        <td><%= h @school.clothes_need %></td>
      </tr>
      <tr>
        <td><label for="accessories_need">教具类：</label></td>
        <td><%= h @school.accessories_need %></td>
      </tr>
      <tr>
        <td><label for="classes_need">学校活动需求：</label></td>
        <td><%= h @school.classes_need %></td>
      </tr>
      <tr>
        <td><label for="teachers_need">支教老师：</label></td>
        <td><%= h @school.teachers_need %></td>
      </tr>
      <tr>
        <td><label for="others_need">其它类：</label></td>
        <td><%= h @school.others_need %></td>
      </tr>
    </table>
  </div>
  <div id="finder-form" style="display:none">
    <table border="0" cellspacing="5" cellpadding="0">
      <tr>
        <td><label for="finder_name">收集人姓名：</label></td>
        <td><%= h @school.finder_name %></td>
      </tr>
      <tr>
        <td><label for="finder_email">Email：</label></td>
        <td><%= h @school.finder_email %></td>
      </tr>
      <tr>
        <td><label for="finder_qq">QQ：</label></td>
        <td><%= h @school.finder_qq %></td>
      </tr>
      <tr>
        <td><label for="finder_msn">MSN：</label></td>
        <td><%= h @school.finder_msn %></td>
      </tr>
      <tr>
        <td><label for="finder_survey_at">调查时间：</label></td>
        <td><%= h @school.finder_survey_at %></td>
      </tr>
    </table>
  </div>

<% end -%>

<% unless @students.blank? -%>
<h2>该校学生 &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp;</h2>
<table border="0" cellspacing="0" cellpadding="2" class="left ol" width="100%">
  <tr>
    <th>名字</th>
    <th>性别</th>
    <th>出生年份</th>
    <th>入学年份</th>
  </tr>
  <% @students.each do |stu| -%>
  <tr>
    <td><%= link_to stu.full_name, student_url(@school.id, stu.id) %></td>
    <td><%= stu.gender_for_human %></td>
    <td><%= stu.birth.year %></td>
    <td><%= stu.enter_school_year %></td>
  </tr>
  <% end -%>  
</table>
<% end -%>

<% unless @photos.blank? -%>
<h2>学校的照片 &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp;</h2>
<% @photos.each do |photo| -%>
  <%= link_to image_tag(photo.public_filename(:small)), photo_url(photo) %>
<% end -%>
<% end -%>
<h2>来自用户的消息 &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp;</h2>
<p style="color:red">如果你知道关于学校的最新情况，请写在下面</p>
<% @comments.each do |cmt| -%>
  <div class="cmt-item" style="margin-bottom:10px">
    <div style="float:left;margin:0 8px 0 0">
      <%= avatar_for cmt.user, "large" %><br />
    </div>
    <div style="margin-left:50px">
      <div>
        <div style="background-color:#ffc">
          <h2><%= h cmt.title %></h2>
        </div>
        
        <% if cmt.editable_by?(current_user) -%>
        <span style="float:right">
          <%= link_to "修改", school_edit_comment_path(@school.id, cmt.id) %>
          <%= link_to "删除", school_comment_path(@school.id, cmt.id), :method => 'delete', :confirm => "您确定要删除自己的消息么？" %>
        </span>
        <% end -%>
        
        <%= link_to cmt.user.login, user_path(cmt.user) %><span class="tip"> 写于 <%= show_datetime cmt.created_at %></span> <span style="color:red"><%= "重要信息" if cmt.include_update? %></span>
      </div>
      <div><%= cmt.content_html %></div>
    </div>
  </div>
<% end -%>

<% if logged_in? -%>
  <% form_for :comment, :url => school_comments_path(:school_id => @school.id) do |f| -%>
    <%= render :partial => 'school_comments/form', :object => f, :locals => {:title => "Re:#{@school.title}"} %>
    <p><%= submit_tag "发布消息" %></p>
  <% end -%>
<% else -%>
  <%= link_to "登录", login_url %>后你也可以发表评论或消息
<% end -%>

<script type="text/javascript">
function show_form (id) {
  Element.hide('base-form');
  Element.hide('traffic-form');
  Element.hide('require-form');
  Element.hide('finder-form');
  $('base-li').className = "";
  $('traffic-li').className = "";
  $('require-li').className = "";
  $('finder-li').className = "";
  
  Element.show(id+"-form");
  $(id+'-li').className = "current";
}
</script>